// Fill out your copyright notice in the Description page of Project Settings.


#include "MyUserWidget.h"

void UMyUserWidget::AddPolygonObj()
{
	FPolygonObj Obj;
	FPolygonObjArr.Add(Obj);
}

int UMyUserWidget::GetPolygonObjCount()
{
	return FPolygonObjArr.Num();
}

void UMyUserWidget::AddPolygonData(FVector2D data)
{
	FPolygonObj& tempObj = FPolygonObjArr.Last();
	tempObj.PolygonArr.Add(data);
}

int UMyUserWidget::GetCurPolygonDataCount()
{
	return FPolygonObjArr.Last().PolygonArr.Num();
}

bool UMyUserWidget::IsPolygonInsidePolygon(const TArray<FVector2D>& SmallPolygon, const TArray<FVector2D>& LargePolygon)
{
	for (const FVector2D& Vertex : SmallPolygon) {
		// 检查小多边形的每个顶点是否都在大多边形内
		if (!IsPointInPolygon(Vertex, LargePolygon)) {
			return false; // 如果有一个顶点不在大多边形内，返回false
		}
	}
	return true; // 如果所有顶点都在大多边形内，返回true
}

bool UMyUserWidget::IsPointInPolygon(const FVector2D& Point, const TArray<FVector2D>& Polygon)
{
	int32 NumVertices = Polygon.Num();
	bool bIsInside = false;

	for (int32 i = 0, j = NumVertices - 1; i < NumVertices; j = i++)
	{
		if (((Polygon[i].Y > Point.Y) != (Polygon[j].Y > Point.Y)) &&
			(Point.X < (Polygon[j].X - Polygon[i].X) * (Point.Y - Polygon[i].Y) / (Polygon[j].Y - Polygon[i].Y) + Polygon[i].X))
		{
			bIsInside = !bIsInside;
		}
	}
	return bIsInside;
}




